<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue2.js"></script>
    <style>
        
        img{
            float: left;
            width: 100px;
        }
        div{
            overflow: hidden; 
            padding: 10px;
        }
        .xiangqingcss{
            position: fixed;
            top: 30px;
            right: 15px;
            height: 200px;
            width: 200px;
            border: 1px solid green;
            background-color: yellow;
        }
    </style>
</head>
<body>
    <div id="box">
        <button @click="handleClick">请求数据</button>
        <film v-for="item in filmDataList" @event="childData" :filmdata="item" :key="item.filmId"></film>
        <xiangqing :filmdata="filmData"></xiangqing>
    </div>
    <script>
        Vue.component("xiangqing",{
            props:{
                filmdata:{
                    type:String,
                    default:''
                }
            },
            template:`<div class="xiangqingcss">{{this.filmdata}}</div>`
        })
        Vue.component("film",{
            props:{
                filmdata:{
                    type:Object,
                    default:[]
                }
            },
            template:`<div>
                            <img :src="filmdata.poster"/>
                            <span>{{filmdata.name}}</span>
                            <button @click="handleClick">详情</button>
                    </div>`,
            methods:{
                handleClick(){
                    this.$emit("event",this.filmdata.synopsis)
                }
            }
        })
        new Vue({
            el:'#box',
            data:{
            filmDataList:[],
            filmData:'',
            },
            methods:{
                handleClick(){
                    fetch("json/maizuo.json")
                    .then(res=>res.json())
                    .then(res=>{
                        this.filmDataList=res.data.films
                    })
                },
                childData(data){
                    console.log(data);
                    this.filmData=data
                }
            },
            watch:{

            },
            computed:{

            }
        })
    </script>
</body>
</html>